<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {

	function __construct() {
        parent::__construct();	
		//$this->isLogin();	
		$this->load->model("master/pegawai"); 
		$this->load->model("master/pendidikan"); 
		$this->load->model("master/jenjang_pendidikan"); 
		$this->load->model("master/pekerjaan"); 
		$this->load->model("master/bulan"); 
		$this->load->model("master/th_ajaran"); 
		$this->load->model("master/kelas"); 
		$this->load->model("master/jabatan"); 
		$this->load->model("master/instansi"); 
		$this->load->model("atur/a_pengguna"); 
		$this->load->model("atur/a_kelas"); 
		$this->load->model("atur/a_non_syahriyah"); 
		$this->load->model("atur/a_syahriyah"); 
		$this->load->model("atur/a_subsidi"); 
		$this->load->model("atur/a_bulan"); 
		$this->load->model("atur/a_jabatan"); 
		$this->load->model("bagi/b_kelas"); 
		$this->load->model("registrasi/r_tholabah"); 
	}
	/*
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Maaf, Anda belum Masuk.');
			redirect('login');	
		}
	}
	*/
	

	function index()
	{
		$data['main_view']='admin/dashboard';
		$this->load->view('index',$data);
	}
	
	public function cek_no_tlp($str)
	{
		if ($str == '+62 ')
		{
			$this->form_validation->set_message('cek_no_tlp', 'Field %s  harus diisi');
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	
	public function cek_pilih_th_ajaran($str)
	{
		if ($str == '- Pilih Tahun Ajaran -')
		{
			$this->form_validation->set_message('cek_pilih_th_ajaran', 'Field %s  harus dipilih');
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	
	public function cek_pilih_kelas($str)
	{
		if ($str == '- Pilih Kelas -' || $str == '- Kelas Tidak Tersedia -')
		{
			$this->form_validation->set_message('cek_pilih_kelas', 'Field %s  harus dipilih');
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	
	public function cek_pilih_jenjang($str)
	{
		if ($str == '- Pilih Jenjang -' || $str == '- Jenjang Tidak Tersedia -')
		{
			$this->form_validation->set_message('cek_pilih_jenjang', 'Field %s  harus dipilih');
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
/*	===========================================================
	FUNGSI-FUNGSI TABEL MASTER
	===========================================================
	===========================================================
	PEGAWAI
	===========================================================*/
	function m_pegawai_add()
	{
		$data['main_view']='admin/master/pegawai/pegawai-add';
		$this->load->view('index',$data);
	}
	
	function m_pegawai_add_exe()
	{
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('nama_lengkap', 'Nama Lengkap', 'required');		
		$this->form_validation->set_rules('t_lahir', 'Nama Tempat Lahir', 'required');
		$this->form_validation->set_rules('tgl_lahir', 'Tanggal Lahir', 'required');
		$this->form_validation->set_rules('no_tlp', 'Telepon/Hp', 'callback_cek_no_tlp');
		$this->form_validation->set_rules('alamat', 'Alamat', 'required');
		if ($this->form_validation->run() == FALSE)
        {
			$data['main_view']='admin/master/pegawai/pegawai-add';
			$this->load->view('index',$data);
        }
        else
        {
			$tgl = $this->input->post('tgl_lahir');
			$tglMySQL = date("Y-m-d", strtotime ($tgl));
			$noTlp = preg_replace("/[^0-9]/", "", $this->input->post('no_tlp'));
			$dataInsert = array(
				'nama_lengkap' => $this->input->post('nama_lengkap'),
				't_lahir' => $this->input->post('t_lahir'),
				'tgl_lahir' => $tglMySQL,
				'no_tlp' => $noTlp,
				'alamat' => $this->input->post('alamat')
			);
			$this->pegawai->add($dataInsert);
			redirect ('admin/m_pegawai');
		}		
	}
	
	function m_pegawai()
	{
		$data['list'] = $this->pegawai->read();
		$data['main_view']='admin/master/pegawai/pegawai-read';
		$this->load->view('index',$data);
	}
	
	function m_pegawai_edit($id_pegawai)
	{
		$id_pegawai = $this->security->xss_clean($this->uri->segment(3));
		$data['list']=$this->pegawai->edit($id_pegawai);
		$data['main_view']='admin/master/pegawai/pegawai-edit';
		$this->load->view('index',$data);
	}
	
	function m_pegawai_update()
	{
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('nama_lengkap', 'Nama Lengkap', 'required');		
		$this->form_validation->set_rules('t_lahir', 'Nama Tempat Lahir', 'required');
		$this->form_validation->set_rules('tgl_lahir', 'Tanggal Lahir', 'required');
		$this->form_validation->set_rules('no_tlp', 'Telepon/Hp', 'callback_cek_no_tlp');
		$this->form_validation->set_rules('alamat', 'Alamat', 'required');
		if ($this->form_validation->run() == FALSE)
        {
			$id_pegawai = $this->security->xss_clean($this->uri->segment(3));
			$data['list']=$this->pegawai->edit($id_pegawai);
			$data['main_view']='admin/master/pegawai/pegawai-edit';
			$this->load->view('index',$data);
		}
		else
		{
			$id_pegawai=$this->input->post('id_pegawai');
			$tgl = $this->input->post('tgl_lahir');
			$tglMySQL = date("Y-m-d", strtotime ($tgl));
			$noTlp = preg_replace("/[^0-9]/", "", $this->input->post('no_tlp'));
			$dataInsert=array(
				'nama_lengkap'=>$this->input->post('nama_lengkap'),
				't_lahir'=>$this->input->post('t_lahir'),
				'tgl_lahir'=>$tglMySQL,
				'no_tlp'=>$noTlp,
				'alamat'=>$this->input->post('alamat')
			);
			$this->pegawai->update($id_pegawai,$dataInsert);
			redirect('admin/m_pegawai');
		}
	}
	
	function m_pegawai_delete()
	{
		$id_pegawai = $this->security->xss_clean($this->uri->segment(3));
		$this->pegawai->delete($id_pegawai);
		redirect('admin/m_pegawai');
	}
/*	===========================================================
	PENDIDIKAN
	===========================================================*/
	function m_pendidikan_add_exe()
	{
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('pendidikan', 'Pendidikan', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list'] = $this->pendidikan->read();
			$data['main_view']='admin/master/pendidikan/pendidikan-add-read';
			$this->load->view('index',$data);			
		}else
		{
			$dataInsert = array(
				'pendidikan' => $this->input->post('pendidikan')
			);
			$this->pendidikan->add($dataInsert);
			redirect ('admin/m_pendidikan');
		}
	}
	
	function m_pendidikan()
	{
		$data['list'] = $this->pendidikan->read();
		$data['main_view']='admin/master/pendidikan/pendidikan-add-read';
		$this->load->view('index',$data);
	}
	
	function m_pendidikan_edit($id_pendidikan)
	{
		$id_pendidikan = $this->security->xss_clean($this->uri->segment(3));
		
		$data['list_edit']=$this->pendidikan->edit($id_pendidikan);
		$data['list_read'] = $this->pendidikan->read();
		
		$data['main_view']='admin/master/pendidikan/pendidikan-edit-read';
		$this->load->view('index',$data);
	}
	
	function m_pendidikan_update()
	{
		$id_pendidikan=$this->input->post('id_pendidikan');
		$dataInsert=array(
			'pendidikan'=>$this->input->post('pendidikan')
		);
		$this->pendidikan->update($id_pendidikan,$dataInsert);
		redirect('admin/m_pendidikan');
	}
	
	function m_pendidikan_delete()
	{
		$id_pendidikan = $this->security->xss_clean($this->uri->segment(3));
		$this->pendidikan->delete($id_pendidikan);
		redirect('admin/m_pendidikan');
	}
/*	===========================================================
	JENJANG PENDIDIKAN
	===========================================================*/
	function m_jenjang_pendidikan_add_exe()
	{	
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('j_pendidikan', 'Jenjang Pendidikan', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list'] = $this->jenjang_pendidikan->read();
			$data['main_view']='admin/master/jenjang-pendidikan/jenjang-pendidikan-add-read';
			$this->load->view('index',$data);
		}
		else
		{
			$dataInsert = array(
				'j_pendidikan' => $this->input->post('j_pendidikan')
			);
			$this->jenjang_pendidikan->add($dataInsert);
			redirect ('admin/m_jenjang_pendidikan');
		}
	}
	
	function m_jenjang_pendidikan()
	{
		$data['list'] = $this->jenjang_pendidikan->read();
		$data['main_view']='admin/master/jenjang-pendidikan/jenjang-pendidikan-add-read';
		$this->load->view('index',$data);
	}
	
	function m_jenjang_pendidikan_edit($id_j_pendidikan)
	{
		$id_j_pendidikan = $this->security->xss_clean($this->uri->segment(3));
		
		$data['list_edit']=$this->jenjang_pendidikan->edit($id_j_pendidikan);
		$data['list_read'] = $this->jenjang_pendidikan->read();
		
		$data['main_view']='admin/master/jenjang-pendidikan/jenjang-pendidikan-edit-read';
		$this->load->view('index',$data);
	}
	
	function m_jenjang_pendidikan_update()
	{	
		$id_j_pendidikan=$this->input->post('id_j_pendidikan');
		$dataInsert=array(
			'j_pendidikan'=>$this->input->post('j_pendidikan')
		);
		$this->jenjang_pendidikan->update($id_j_pendidikan,$dataInsert);
		redirect('admin/m_jenjang_pendidikan');
	}
	
	function m_jenjang_pendidikan_delete()
	{
		$id_j_pendidikan = $this->security->xss_clean($this->uri->segment(3));
		$this->jenjang_pendidikan->delete($id_j_pendidikan);
		redirect('admin/m_jenjang_pendidikan');
	}
/*	===========================================================
	PEKERJAAN
	===========================================================*/
	function m_pekerjaan_add_exe()
	{	
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('pekerjaan', 'Pekerjaan', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list'] = $this->pekerjaan->read();
			$data['main_view']='admin/master/pekerjaan/pekerjaan-add-read';
			$this->load->view('index',$data);
		}
		else
		{
			$dataInsert = array(
				'pekerjaan' => $this->input->post('pekerjaan')
			);
			$this->pekerjaan->add($dataInsert);
			redirect ('admin/m_pekerjaan');
		}
	}
	
	function m_pekerjaan()
	{
		$data['list'] = $this->pekerjaan->read();
		$data['main_view']='admin/master/pekerjaan/pekerjaan-add-read';
		$this->load->view('index',$data);
	}
	
	function m_pekerjaan_edit($id_pekerjaan)
	{
		$id_pekerjaan = $this->security->xss_clean($this->uri->segment(3));
		
		$data['list_edit']=$this->pekerjaan->edit($id_pekerjaan);
		$data['list_read'] = $this->pekerjaan->read();
		
		$data['main_view']='admin/master/pekerjaan/pekerjaan-edit-read';
		$this->load->view('index',$data);
	}
	
	function m_pekerjaan_update()
	{
		$id_pekerjaan=$this->input->post('id_pekerjaan');
		$dataInsert=array(
			'pekerjaan'=>$this->input->post('pekerjaan')
		);
		$this->pekerjaan->update($id_pekerjaan,$dataInsert);
		redirect('admin/m_pekerjaan');
	}
	
	function m_pekerjaan_delete()
	{
		$id_pekerjaan = $this->security->xss_clean($this->uri->segment(3));
		$this->pekerjaan->delete($id_pekerjaan);
		redirect('admin/m_pekerjaan');
	}
/*	===========================================================
	BULAN	
	===========================================================*/
	function m_bulan_add_exe()
	{	
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('bulan', 'Bulan', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list'] = $this->bulan->read();
			$data['main_view']='admin/master/bulan/bulan-add-read';
			$this->load->view('index',$data);
		}
		else
		{
			$dataInsert = array(
				'bulan' => $this->input->post('bulan')
			);
			$this->bulan->add($dataInsert);
			redirect ('admin/m_bulan');
		}
	}
	
	function m_bulan()
	{
		$data['list'] = $this->bulan->read();
		$data['main_view']='admin/master/bulan/bulan-add-read';
		$this->load->view('index',$data);
	}
	
	function m_bulan_edit($id_bulan)
	{
		$id_bulan = $this->security->xss_clean($this->uri->segment(3));
		
		$data['list_edit']=$this->bulan->edit($id_bulan);
		$data['list_read'] = $this->bulan->read();
		
		$data['main_view']='admin/master/bulan/bulan-edit-read';
		$this->load->view('index',$data);
	}
	
	function m_bulan_update()
	{
		$id_bulan=$this->input->post('id_bulan');
		$dataInsert=array(
			'bulan'=>$this->input->post('bulan')
		);
		$this->bulan->update($id_bulan,$dataInsert);
		redirect('admin/m_bulan');
	}
	
	function m_bulan_delete()
	{
		$id_bulan = $this->security->xss_clean($this->uri->segment(3));
		$this->bulan->delete($id_bulan);
		redirect('admin/m_bulan');
	}
/*	===========================================================
	TAHUN AJARAN	
	===========================================================*/	
	function m_th_ajaran_add_exe()
	{
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('th_ajaran', 'Tahun Ajaran', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list'] = $this->th_ajaran->read();
			$data['main_view']='admin/master/th-ajaran/th-ajaran-add-read';
			$this->load->view('index',$data);			
		}
		else
		{
			$dataInsert = array(
				'th_ajaran' => $this->input->post('th_ajaran')
			);
			$this->th_ajaran->add($dataInsert);
			redirect ('admin/m_th_ajaran');
		}
	}
	
	function m_th_ajaran()
	{
		$data['list'] = $this->th_ajaran->read();
		$data['main_view']='admin/master/th-ajaran/th-ajaran-add-read';
		$this->load->view('index',$data);
	}
	
	function m_th_ajaran_edit($id_th_ajaran)
	{
		$id_th_ajaran = $this->security->xss_clean($this->uri->segment(3));
		
		$data['list_edit']=$this->th_ajaran->edit($id_th_ajaran);
		$data['list_read'] = $this->th_ajaran->read();
		
		$data['main_view']='admin/master/th-ajaran/th-ajaran-edit-read';
		$this->load->view('index',$data);
	}
	
	function m_th_ajaran_update()
	{
		$id_th_ajaran=$this->input->post('id_th_ajaran');
		$dataInsert=array(
			'th_ajaran'=>$this->input->post('th_ajaran')
		);
		$this->th_ajaran->update($id_th_ajaran,$dataInsert);
		redirect('admin/m_th_ajaran');
	}
	
	function m_th_ajaran_delete()
	{
		$id_th_ajaran = $this->security->xss_clean($this->uri->segment(3));
		$this->th_ajaran->delete($id_th_ajaran);
		redirect('admin/m_th_ajaran');
	}
/*	===========================================================
	KELAS
	===========================================================*/	
	function m_kelas_add_exe()
	{
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('kelas', 'Kelas', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list'] = $this->kelas->read();
			$data['main_view']='admin/master/kelas/kelas-add-read';
			$this->load->view('index',$data);
		}
		else
		{
			$dataInsert = array(
				'kelas' => $this->input->post('kelas')
			);
			$this->kelas->add($dataInsert);
			redirect ('admin/m_kelas');
		}
	}
	
	function m_kelas()
	{
		$data['list'] = $this->kelas->read();
		$data['main_view']='admin/master/kelas/kelas-add-read';
		$this->load->view('index',$data);
	}
	
	function m_kelas_edit($id_kelas)
	{
		$id_kelas = $this->security->xss_clean($this->uri->segment(3));
		
		$data['list_edit']=$this->kelas->edit($id_kelas);
		$data['list_read'] = $this->kelas->read();
		
		$data['main_view']='admin/master/kelas/kelas-edit-read';
		$this->load->view('index',$data);
	}
	
	function m_kelas_update()
	{
		$id_kelas=$this->input->post('id_kelas');
		$dataInsert=array(
			'kelas'=>$this->input->post('kelas')
		);
		$this->kelas->update($id_kelas,$dataInsert);
		redirect('admin/m_kelas');
	}
	
	function m_kelas_delete()
	{
		$id_kelas = $this->security->xss_clean($this->uri->segment(3));
		$this->kelas->delete($id_kelas);
		redirect('admin/m_kelas');
	}
/*	===========================================================
	JABATAN
	===========================================================*/	
	function m_jabatan_add_exe()
	{
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('jabatan', 'Jabatan', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list'] = $this->jabatan->read();
			$data['main_view']='admin/master/jabatan/jabatan-add-read';
			$this->load->view('index',$data);
		}
		else
		{
			$dataInsert = array(
				'jabatan' => $this->input->post('jabatan')
			);
			$this->jabatan->add($dataInsert);
			redirect ('admin/m_jabatan');
		}
	}
	
	function m_jabatan()
	{
		$data['list'] = $this->jabatan->read();
		$data['main_view']='admin/master/jabatan/jabatan-add-read';
		$this->load->view('index',$data);
	}
	
	function m_jabatan_edit($id_jabatan)
	{
		$id_jabatan = $this->security->xss_clean($this->uri->segment(3));
		
		$data['list_edit']=$this->jabatan->edit($id_jabatan);
		$data['list_read'] = $this->jabatan->read();
		
		$data['main_view']='admin/master/jabatan/jabatan-edit-read';
		$this->load->view('index',$data);
	}
	
	function m_jabatan_update()
	{
		$id_jabatan=$this->input->post('id_jabatan');
		$dataInsert=array(
			'jabatan'=>$this->input->post('jabatan')
		);
		$this->jabatan->update($id_jabatan,$dataInsert);
		redirect('admin/m_jabatan');
	}
	
	function m_jabatan_delete()
	{
		$id_jabatan = $this->security->xss_clean($this->uri->segment(3));
		$this->jabatan->delete($id_jabatan);
		redirect('admin/m_jabatan');
	}
/*	===========================================================
	INSTANSI
	===========================================================*/
	function m_instansi_add()
	{
		$data['main_view']='admin/master/instansi/instansi-add';
		$this->load->view('index',$data);
	}
	
	function m_instansi_add_exe()
	{	
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('instansi', 'Instansi', 'required');		
		$this->form_validation->set_rules('alamat', 'Alamat', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
		$this->form_validation->set_rules('no_tlp', 'Telepon/Hp', 'callback_cek_no_tlp');
		if ($this->form_validation->run() == FALSE)
        {
			$data['main_view']='admin/master/instansi/instansi-add';
			$this->load->view('index',$data);
		}
		else
		{
			$noTlp = preg_replace("/[^0-9]/", "", $this->input->post('no_tlp'));
			$dataInsert = array(
				'instansi' => $this->input->post('instansi'),
				'alamat' => $this->input->post('alamat'),
				'email' => $this->input->post('email'),
				'no_tlp' => $noTlp
			);
			$this->instansi->add($dataInsert);
			redirect ('admin/m_instansi');
		}
	}
	
	function m_instansi()
	{
		$data['list'] = $this->instansi->read();
		$data['main_view']='admin/master/instansi/instansi-read';
		$this->load->view('index',$data);
	}
	
	function m_instansi_edit($id_instansi)
	{
		$id_instansi = $this->security->xss_clean($this->uri->segment(3));		
		$data['list']=$this->instansi->edit($id_instansi);		
		$data['main_view']='admin/master/instansi/instansi-edit';
		$this->load->view('index',$data);
	}
	
	function m_instansi_update()
	{
		$id_instansi=$this->input->post('id_instansi');
		$noTlp = preg_replace("/[^0-9]/", "", $this->input->post('no_tlp'));
		$dataInsert=array(
			'instansi'=>$this->input->post('instansi'),
			'alamat'=>$this->input->post('alamat'),
			'email'=>$this->input->post('email'),
			'no_tlp'=>$noTlp
		);
		$this->instansi->update($id_instansi,$dataInsert);
		redirect('admin/m_instansi');
	}
	
	function m_instansi_delete()
	{
		$id_instansi = $this->security->xss_clean($this->uri->segment(3));
		$this->instansi->delete($id_instansi);
		redirect('admin/m_instansi');
	}
/*	===========================================================
	FUNGSI-FUNGSI TABEL PENGATURAN
	===========================================================
	===========================================================
	PENGATURAN PENGGUNA
	===========================================================*/
	function a_pengguna_add()
	{	
		$data['list'] = $this->pegawai->read4pengguna();
		
		$data['main_view']='admin/atur/pengguna/pengguna-add';
		$this->load->view('index',$data);
	}
	
	function a_pengguna_add_exe()
	{
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('username', 'Username', 'required|is_unique[pengguna.username]');		
		$this->form_validation->set_rules('sandi', 'Sandi', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list'] = $this->pegawai->read4pengguna();
		
			$data['main_view']='admin/atur/pengguna/pengguna-add';
			$this->load->view('index',$data);
		}
		else
		{
			$dataInsert = array(
				'id_pegawai' => $this->input->post('id_pegawai'),
				'username' => $this->input->post('username'),
				'sandi' => md5 ($this->input->post('sandi')),
				'role' => $this->input->post('role')
			);
			$this->a_pengguna->add($dataInsert);
			redirect ('admin/a_pengguna');
		}
	}
	
	function a_pengguna()
	{
		$data['list'] = $this->a_pengguna->read();
		$data['main_view']='admin/atur/pengguna/pengguna-read';
		$this->load->view('index',$data);
	}
	
	function a_pengguna_edit($id_pengguna)
	{
		$id_pengguna = $this->security->xss_clean($this->uri->segment(3));				
		$data['list']=$this->a_pengguna->edit($id_pengguna);		
		$data['main_view']='admin/atur/pengguna/pengguna-edit';
		$this->load->view('index',$data);
	}
	
	function a_pengguna_update()
	{
		$id_pengguna=$this->input->post('id_pengguna');
		$sandi = $this->input->post('sandi');
		if ($sandi !=''){
			$dataInsert=array(
				'username'=>$this->input->post('username'),
				'sandi'=>md5($this->input->post('sandi')),
				'role'=>$this->input->post('role')
			);
		} else {		
			$dataInsert=array(
				'username'=>$this->input->post('username'),
				'role'=>$this->input->post('role')
			);
		};
		$this->a_pengguna->update($id_pengguna,$dataInsert);
		redirect('admin/a_pengguna');
	}
	
	function a_pengguna_delete()
	{
		$id_pengguna = $this->security->xss_clean($this->uri->segment(3));
		$this->a_pengguna->delete($id_pengguna);
		redirect('admin/a_pengguna');
	}	
/*	===========================================================
	PENGATURAN KELAS
	===========================================================*/
	function a_kelas_add()
	{	
		$data['list_ta'] = $this->th_ajaran->read();		
		$data['list_p'] = $this->pegawai->read();		
		
		$data['main_view']='admin/atur/kelas/kelas-add';
		$this->load->view('index',$data);
	}
	
	function a_kelas_add_exe()
	{	
		$this->load->library('form_validation');	
		$this->form_validation->set_rules('id_th_ajaran', 'Tahun Ajaran', 'callback_cek_pilih_th_ajaran');
		$this->form_validation->set_rules('id_kelas', 'Kelas', 'callback_cek_pilih_kelas');
		$this->form_validation->set_rules('id_pegawai', 'Wali Kelas', 'required');
		if ($this->form_validation->run() == FALSE)
        {
			$data['list_ta'] = $this->th_ajaran->read();		
			$data['list_p'] = $this->pegawai->read();
			
			$data['main_view']='admin/atur/kelas/kelas-add';
			$this->load->view('index',$data);
		}
		else
		{
			$dataInsert = array(					
				'id_th_ajaran' => $this->input->post('id_th_ajaran'),
				'id_kelas' => $this->input->post('id_kelas'),
				'id_pegawai' => $this->input->post('id_pegawai')
			);
			$this->a_kelas->add($dataInsert);
			redirect ('admin/a_kelas');
		}
		
	}
	
	function a_kelas()
	{
		$data['list'] = $this->a_kelas->read();
		$data['main_view']='admin/atur/kelas/kelas-read';
		$this->load->view('index',$data);
	}
	
	function a_kelas_edit($id_atur_kelas)
	{
		$id_atur_kelas = $this->security->xss_clean($this->uri->segment(3));	
		
		$data['list_k'] = $this->kelas->read();		
		$data['list_p'] = $this->pegawai->read();
		$data['list_ta'] = $this->th_ajaran->read();
		
		$data['list']=$this->a_kelas->edit($id_atur_kelas);		
		//print_r($data['list']);
		$data['main_view']='admin/atur/kelas/kelas-edit';
		$this->load->view('index',$data);
	}
	
	function a_kelas_update()
	{
		$id_atur_kelas=$this->input->post('id_atur_kelas');
		$dataInsert=array(
			'id_pegawai'=>$this->input->post('id_pegawai')
		);
		$this->a_kelas->update($id_atur_kelas,$dataInsert);
		redirect('admin/a_kelas');
	}
	
	function a_kelas_delete()
	{
		$id_atur_kelas = $this->security->xss_clean($this->uri->segment(3));
		$this->a_kelas->delete($id_atur_kelas);
		redirect('admin/a_kelas');
	}	
	
	function a_kelas_kelasnya_th_a()
	{
		$id_th_ajaran = $this->input->post('id_th_ajaran');
		$data['list_k'] = $this->a_kelas->a_kelas_nyath_a($id_th_ajaran);
        $this->load->view('admin/atur/kelas/kelas-kelasnya-th-a',$data);
	}
/*	===========================================================
	PENGATURAN SYAHRIYAH
	===========================================================*/
	function a_syahriyah_add()
	{	
		$data['list_ta'] = $this->th_ajaran->read();
		
		$data['main_view']='admin/atur/syahriyah/syahriyah-add';
		$this->load->view('index',$data);
	}	
	
	function a_syahriyah_add_exe()
	{	
		$this->load->library('form_validation');	
		$this->form_validation->set_rules('id_th_ajaran', 'Tahun Ajaran', 'callback_cek_pilih_th_ajaran');
		$this->form_validation->set_rules('id_j_pendidikan', 'Jenjang Pendidikan', 'callback_cek_pilih_jenjang');
		$this->form_validation->set_rules('besar_sy', 'Besar Syahriyah', 'required');		
		if ($this->form_validation->run() == FALSE)
        {
			$data['list_ta'] = $this->th_ajaran->read();
			
			$data['main_view']='admin/atur/syahriyah/syahriyah-add';
			$this->load->view('index',$data);
		}
		else
		{
			$besar_sy= preg_replace("/[^0-9]/", "", $this->input->post('besar_sy'));
			$dataInsert = array(
				'id_th_ajaran'=>$this->input->post('id_th_ajaran'),
				'id_j_pendidikan'=>$this->input->post('id_j_pendidikan'),				
				'besar_sy'=>$besar_sy
			);
			$this->a_syahriyah->add($dataInsert);
			redirect ('admin/a_syahriyah');
		}
	}
	
	function a_syahriyah()
	{
		$this->load->helper("formatrp");
		$data['list'] = $this->a_syahriyah->read();
		$data['main_view']='admin/atur/syahriyah/syahriyah-read';
		$this->load->view('index',$data);
	}
	
	function a_syahriyah_edit($id_atur_syahriyah)
	{
		$id_atur_syahriyah = $this->security->xss_clean($this->uri->segment(3));	
		$this->load->helper("formatrp");
		
		$data['list_jp'] = $this->jenjang_pendidikan->read();		
		$data['list_ta'] = $this->th_ajaran->read();
		
		$data['list']=$this->a_syahriyah->edit($id_atur_syahriyah);		
		$data['main_view']='admin/atur/syahriyah/syahriyah-edit';
		$this->load->view('index',$data);
	}
	
	function a_syahriyah_update()
	{
		$id_atur_syahriyah=$this->input->post('id_atur_syahriyah');
		$besar_sy= preg_replace("/[^0-9]/", "", $this->input->post('besar_sy'));
		$dataInsert=array(
			'id_j_pendidikan'=>$this->input->post('id_j_pendidikan'),
			'id_th_ajaran'=>$this->input->post('id_th_ajaran'),
			'besar_sy'=>$besar_sy
		);
		$this->a_syahriyah->update($id_atur_syahriyah,$dataInsert);
		redirect('admin/a_syahriyah');
	}
	
	function a_syahriyah_delete()
	{
		$id_atur_syahriyah = $this->security->xss_clean($this->uri->segment(3));
		$this->a_syahriyah->delete($id_atur_syahriyah);
		redirect('admin/a_syahriyah');
	}
	
	function a_syahriyah_j_pendidikannya_th_a()
	{
		$id_th_ajaran = $this->input->post('id_th_ajaran');
		$data['list_jp'] = $this->a_syahriyah->a_j_pendidikannya_th_a($id_th_ajaran);
        $this->load->view('admin/atur/syahriyah/syahriyah-j-pendidikannya-th-a',$data);
	}
/*	===========================================================
	PENGATURAN NON SYAHRIYAH
	===========================================================*/
	function a_non_syahriyah_add()
	{	
		$data['main_view']='admin/atur/non-syahriyah/non-syahriyah-add';
		$this->load->view('index',$data);
	}	
	
	function a_non_syahriyah_add_exe()
	{	
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('nama_non_sy', 'Nama Tagihan', 'required');		
		$this->form_validation->set_rules('besar_bayar', 'Besar Tagihan', 'required');		
		$this->form_validation->set_rules('mulai_bayar', 'Mulai Ditagih', 'required');		
		$this->form_validation->set_rules('akhir_bayar', 'Jatuh Tempo', 'required');		
		$this->form_validation->set_rules('ket', 'Keterangan', 'required');		
		if ($this->form_validation->run() == FALSE)
		{
			$data['main_view']='admin/atur/non-syahriyah/non-syahriyah-add';
			$this->load->view('index',$data);
		}
		else
		{
			$tglM = $this->input->post('mulai_bayar');
			$tglA = $this->input->post('akhir_bayar');
			$tglMulai = date("Y-m-d", strtotime ($tglM));
			$tglAkhir = date("Y-m-d", strtotime ($tglA));
			$besar_bayar= preg_replace("/[^0-9]/", "", $this->input->post('besar_bayar'));
			$dataInsert = array(
				'nama_non_sy' => $this->input->post('nama_non_sy'),
				'besar_bayar' => $besar_bayar,
				'mulai_bayar' => $tglMulai,
				'akhir_bayar' => $tglAkhir,
				'ket' => $this->input->post('ket')
			);
			$this->a_non_syahriyah->add($dataInsert);
			redirect ('admin/a_non_syahriyah');
		}
	}
	
	function a_non_syahriyah()
	{
		$this->load->helper("formatrp");
		$data['list'] = $this->a_non_syahriyah->read();
		$data['main_view']='admin/atur/non-syahriyah/non-syahriyah-read';
		$this->load->view('index',$data);
	}
	
	function a_non_syahriyah_edit($id_atur_non_sy)
	{
		$id_atur_non_sy = $this->security->xss_clean($this->uri->segment(3));
		$this->load->helper("formatrp");
		$data['list']=$this->a_non_syahriyah->edit($id_atur_non_sy);
		$data['main_view']='admin/atur/non-syahriyah/non-syahriyah-edit';
		$this->load->view('index',$data);
	}
	
	function a_non_syahriyah_update()
	{
		$id_atur_non_sy=$this->input->post('id_atur_non_sy');
		$tglM = $this->input->post('mulai_bayar');
		$tglA = $this->input->post('akhir_bayar');
		$tglMulai = date("Y-m-d", strtotime ($tglM));
		$tglAkhir = date("Y-m-d", strtotime ($tglA));
		$besar_bayar= preg_replace("/[^0-9]/", "", $this->input->post('besar_bayar'));
		$dataInsert=array(
			'nama_non_sy' => $this->input->post('nama_non_sy'),
			'besar_bayar' => $besar_bayar,
			'mulai_bayar' => $tglMulai,
			'akhir_bayar' => $tglAkhir,
			'ket' => $this->input->post('ket')
		);
		$this->a_non_syahriyah->update($id_atur_non_sy,$dataInsert);
		redirect('admin/a_non_syahriyah');
	}
	
	function a_non_syahriyah_delete()
	{
		$id_atur_non_sy = $this->security->xss_clean($this->uri->segment(3));
		$this->a_non_syahriyah->delete($id_atur_non_sy);
		redirect('admin/a_non_syahriyah');
	}
/*	===========================================================
	PENGATURAN SUBSIDI
	===========================================================*/
	function a_subsidi_add()
	{	
		$data['list_i'] = $this->instansi->read();	
		$data['error'] = '';
		
		$data['main_view']='admin/atur/subsidi/subsidi-add';
		$this->load->view('index',$data);
	}	
	
	function a_subsidi_add_exe()
	{	
		$nama_asli = $_FILES['file_surat']['name'];	
		$nama_subsidi = $this->input->post('nama_subsidi',TRUE);
		$tanggal = date('Y-m-d');
		
		$config['file_name'] = $tanggal.'_'.'_'.$nama_subsidi.'_'.'_'.$nama_asli;
		$config['upload_path'] = './content/uploads/surat-subsidi';
		$config['allowed_types'] = 'pdf';
		$config['max_size']	= '20480';
		$config['overwrite'] = FALSE;
		
		$this->load->library('upload', $config);
		
		if ((! $this->upload->do_upload('file_surat')))
		{
			$data = array('error' => $this->upload->display_errors('<span class="error">','</span>'));	
			
			$data['list_i'] = $this->instansi->read();	
			$data['main_view']='admin/atur/subsidi/subsidi-add';
			$this->load->view('index',$data);		
		}
		else
		{
			$data = array('upload_data' => $this->upload->data());
			$get_name = $this->upload->data();
			$nama_file = $get_name['file_name'];
			
			$besar_subsidi= preg_replace("/[^0-9]/", "", $this->input->post('besar_subsidi'));
			$tgl = $this->input->post('tgl_terima');
			$tglMySQL = date("Y-m-d", strtotime ($tgl));
			$dataInsert = array(
				'nama_subsidi'=>$this->input->post('nama_subsidi'),
				'id_instansi'=>$this->input->post('id_instansi'),
				'besar_subsidi'=>$besar_subsidi,
				'tgl_terima'=>$tglMySQL,
				'no_surat'=>$this->input->post('no_surat'),
				'file_surat'=>$nama_file,
				'ket'=>$this->input->post('ket')
			);
			$this->a_subsidi->add($dataInsert);
			redirect ('admin/a_subsidi');
		}
	}
	
	function a_subsidi()
	{
		$this->load->helper("formatrp");
		$data['list'] = $this->a_subsidi->read();
		$data['main_view']='admin/atur/subsidi/subsidi-read';
		$this->load->view('index',$data);
	}
	
	function a_subsidi_edit($id_atur_subsidi)
	{
		$id_atur_subsidi = $this->security->xss_clean($this->uri->segment(3));	
		$this->load->helper("formatrp");
		
		$data['list_i'] = $this->instansi->read();		
		$data['error'] = '';
		
		$data['list']=$this->a_subsidi->edit($id_atur_subsidi);		
		$data['main_view']='admin/atur/subsidi/subsidi-edit';
		$this->load->view('index',$data);
	}
	
	function a_subsidi_update()
	{
		$id_atur_subsidi=$this->input->post('id_atur_subsidi');
		$besar_subsidi= preg_replace("/[^0-9]/", "", $this->input->post('besar_subsidi'));
		$tgl = $this->input->post('tgl_terima');
		$tglMySQL = date("Y-m-d", strtotime ($tgl));
			
		$file_surat = $this->input->post('file_surat');
		if ($file_surat !=''){
		
			$nama_asli = $_FILES['file_surat']['name'];	
			$nama_subsidi = $this->input->post('nama_subsidi',TRUE);
			$tanggal = date('Y-m-d');
				
			$config['file_name'] = $tanggal.'_'.'_'.$nama_subsidi.'_'.'_'.$nama_asli;
			$config['upload_path'] = './content/uploads/surat-subsidi';
			$config['allowed_types'] = 'pdf';
			$config['max_size']	= '20480';
			$config['overwrite'] = FALSE;
			
			$this->load->library('upload', $config);
			
			if ((! $this->upload->do_upload('file_surat')))
			{
				$data = array('error' => $this->upload->display_errors('<span class="error">','</span>'));					
				$data['list_i'] = $this->instansi->read();	
				$data['main_view']='admin/atur/subsidi/subsidi-add';
				$this->load->view('index',$data);		
			}
			else
			{		
				$data = array('upload_data' => $this->upload->data());
				$get_name = $this->upload->data();
				$nama_file = $get_name['file_name'];
		
				$dataInsert=array(
					'nama_subsidi'=>$this->input->post('nama_subsidi'),
					'id_instansi'=>$this->input->post('id_instansi'),
					'besar_subsidi'=>$besar_subsidi,
					'tgl_terima'=>$tglMySQL,
					'no_surat'=>$this->input->post('no_surat'),
					'file_surat'=>$nama_file,
					'ket'=>$this->input->post('ket')
				);	
				$this->a_subsidi->update($id_atur_subsidi,$dataInsert);
				redirect('admin/a_subsidi');
			}
		}
		else
		{
			$dataInsert=array(
				'nama_subsidi'=>$this->input->post('nama_subsidi'),
				'id_instansi'=>$this->input->post('id_instansi'),
				'besar_subsidi'=>$besar_subsidi,
				'tgl_terima'=>$tglMySQL,
				'no_surat'=>$this->input->post('no_surat'),
				'ket'=>$this->input->post('ket')
			);
			$this->a_subsidi->update($id_atur_subsidi,$dataInsert);
			redirect('admin/a_subsidi');
		}		
	}
	
	function a_subsidi_delete()
	{
		$id_atur_subsidi = $this->security->xss_clean($this->uri->segment(3));
		$this->a_subsidi->delete($id_atur_subsidi);
		redirect('admin/a_subsidi');
	}
/*	===========================================================
	PENGATURAN BULAN
	===========================================================*/
	function a_bulan_add()
	{	
		$data['list_b'] = $this->bulan->read();	
		$data['list_ta'] = $this->th_ajaran->read();	
		
		$data['main_view']='admin/atur/bulan/bulan-add';
		$this->load->view('index',$data);
	}	
	
	function a_bulan_add_exe()
	{	
		$this->load->library('form_validation');			
		$this->form_validation->set_rules('mulai', 'Mulai', 'required');		
		$this->form_validation->set_rules('akhir', 'Akhir', 'required');		
		if ($this->form_validation->run() == FALSE)
		{
			$data['list_b'] = $this->bulan->read();	
			$data['list_ta'] = $this->th_ajaran->read();	
			
			$data['main_view']='admin/atur/bulan/bulan-add';
			$this->load->view('index',$data);
		}
		else
		{
			$tglM = $this->input->post('mulai');
			$tglMulai = date("Y-m-d", strtotime ($tglM));
			$tglA = $this->input->post('akhir');
			$tglAkhir = date("Y-m-d", strtotime ($tglA));
			$dataInsert = array(
				'id_bulan'=>$this->input->post('id_bulan'),
				'mulai'=>$tglMulai,
				'akhir'=>$tglAkhir,
				'id_th_ajaran'=>$this->input->post('id_th_ajaran')
			);
			$this->a_bulan->add($dataInsert);
			redirect ('admin/a_bulan');
		}
	}
	
	function a_bulan()
	{
		$data['list'] = $this->a_bulan->read();
		$data['main_view']='admin/atur/bulan/bulan-read';
		$this->load->view('index',$data);
	}
	
	function a_bulan_edit($id_atur_bulan)
	{
		$id_atur_bulan = $this->security->xss_clean($this->uri->segment(3));	
		
		$data['list_b'] = $this->bulan->read();	
		$data['list_ta'] = $this->th_ajaran->read();	
		
		$data['list']=$this->a_bulan->edit($id_atur_bulan);		
		$data['main_view']='admin/atur/bulan/bulan-edit';
		$this->load->view('index',$data);
	}
	
	function a_bulan_update()
	{
		$id_atur_bulan=$this->input->post('id_atur_bulan');
		$tglM = $this->input->post('mulai');
		$tglMulai = date("Y-m-d", strtotime ($tglM));
		$tglA = $this->input->post('akhir');
		$tglAkhir = date("Y-m-d", strtotime ($tglA));
		$dataInsert=array(
			'id_bulan'=>$this->input->post('id_bulan'),
			'mulai'=>$tglMulai,
			'akhir'=>$tglAkhir,
			'id_th_ajaran'=>$this->input->post('id_th_ajaran')
		);
		$this->a_bulan->update($id_atur_bulan,$dataInsert);
		redirect('admin/a_bulan');
	}
	
	function a_bulan_delete()
	{
		$id_atur_bulan = $this->security->xss_clean($this->uri->segment(3));
		$this->a_bulan->delete($id_atur_bulan);
		redirect('admin/a_bulan');
	}
/*	===========================================================
	PENGATURAN JABATAN
	===========================================================*/
	function a_jabatan_add()
	{	
		$data['list_p'] = $this->pegawai->read();	
		$data['list_j'] = $this->jabatan->read();	
		
		$data['main_view']='admin/atur/jabatan/jabatan-add';
		$this->load->view('index',$data);
	}	
	
	function a_jabatan_add_exe()
	{	
		$this->load->library('form_validation');			
		$this->form_validation->set_rules('mulai', 'Mulai', 'required');		
		$this->form_validation->set_rules('akhir', 'Akhir', 'required');		
		if ($this->form_validation->run() == FALSE)
		{
			$data['list_p'] = $this->pegawai->read();	
			$data['list_j'] = $this->jabatan->read();	
			
			$data['main_view']='admin/atur/jabatan/jabatan-add';
			$this->load->view('index',$data);
		}
		else
		{
			$tglM = $this->input->post('mulai');
			$tglMulai = date("Y-m-d", strtotime ($tglM));
			$tglA = $this->input->post('akhir');
			$tglAkhir = date("Y-m-d", strtotime ($tglA));
			$dataInsert = array(
				'id_pegawai'=>$this->input->post('id_pegawai'),
				'id_jabatan'=>$this->input->post('id_jabatan'),
				'mulai'=>$tglMulai,
				'akhir'=>$tglAkhir
			);
			$this->a_jabatan->add($dataInsert);
			redirect ('admin/a_jabatan');
		}
	}
	
	function a_jabatan()
	{
		$data['list'] = $this->a_jabatan->read();
		$data['main_view']='admin/atur/jabatan/jabatan-read';
		$this->load->view('index',$data);
	}
	
	function a_jabatan_edit($id_atur_jabatan)
	{
		$id_atur_jabatan = $this->security->xss_clean($this->uri->segment(3));	
		
		$data['list_p'] = $this->pegawai->read();	
		$data['list_j'] = $this->jabatan->read();	
		
		$data['list']=$this->a_jabatan->edit($id_atur_jabatan);		
		$data['main_view']='admin/atur/jabatan/jabatan-edit';
		$this->load->view('index',$data);
	}
	
	function a_jabatan_update()
	{
		$id_atur_jabatan=$this->input->post('id_atur_jabatan');
		$tglM = $this->input->post('mulai');
		$tglMulai = date("Y-m-d", strtotime ($tglM));
		$tglA = $this->input->post('akhir');
		$tglAkhir = date("Y-m-d", strtotime ($tglA));
		$dataInsert=array(
			'id_pegawai'=>$this->input->post('id_pegawai'),
			'id_jabatan'=>$this->input->post('id_jabatan'),
			'mulai'=>$tglMulai,
			'akhir'=>$tglAkhir
		);
		$this->a_jabatan->update($id_atur_jabatan,$dataInsert);
		redirect('admin/a_jabatan');
	}
	
	function a_jabatan_delete()
	{
		$id_atur_jabatan = $this->security->xss_clean($this->uri->segment(3));
		$this->a_jabatan->delete($id_atur_jabatan);
		redirect('admin/a_jabatan');
	}
/*	===========================================================
	FUNGSI-FUNGSI TABEL PEMBAGIAN
	===========================================================
	===========================================================
	PEMBAGIAN KELAS
	===========================================================*/
	function b_kelas_add()
	{	
		
	}	
	
	function b_kelas()
	{
		$data['list'] = $this->b_kelas->read();
		$data['main_view']='admin/bagi/kelas/kelas-read';
		$this->load->view('index',$data);
	}
/*	===========================================================
	FUNGSI-FUNGSI TABEL REGISTRASI
	===========================================================
	===========================================================
	REGISTRASI THOLABAH
	===========================================================*/
	function r_tholabah_add()
	{	
		$data['list_p'] = $this->pegawai->read();	
		$data['list_j'] = $this->jabatan->read();	
		
		$data['main_view']='admin/registrasi/tholabah/tholabah-add';
		$this->load->view('index',$data);
	}	
	
	function r_tholabah()
	{
		$data['list'] = $this->r_tholabah->read();
		$data['main_view']='admin/registrasi/tholabah/tholabah-read';
		$this->load->view('index',$data);
	}
}